package com.wingice.system.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wingice.common.page.EntityPageBean;
import com.wingice.common.web.ErrorCodeInfo;
import com.wingice.system.entity.SysDictionary;
import com.wingice.system.exception.ResultBean;
import com.wingice.system.service.SysDictionaryService;
import com.wingice.system.validator.dictionary.SysDictionaryValidator;
import com.wingice.system.vo.dictionary.SysDictionaryView;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/sysDictionary")
@Tag(name = "字典类型管理")
public class SysDictionaryController {

    @Resource
    private SysDictionaryService sysDictionaryService;

    /**
     * @param sysDictionary 字典信息
     * @description 新增字典类型
     * @author 胡昊
     * @email huhao9277@gmail.com
     * @date 2021/3/5 12:37
     */
    @PostMapping("/insert")
    @Operation(summary = "新增字典类型")
    public ResultBean<Boolean> insert(@RequestBody SysDictionary sysDictionary) {
        SysDictionaryValidator.insertValidate(sysDictionary);
        return ResultBean.restResult(sysDictionaryService.save(sysDictionary), ErrorCodeInfo.OK);
    }

    /**
     * @param idList 待删除id列表
     * @description 批量删除字典类型
     * @author 胡昊
     * @email huhao9277@gmail.com
     * @date 2021/3/5 12:40
     */
    @DeleteMapping("/deleteBatch")
    @Operation(summary = "批量删除字典类型")
    public ResultBean<Boolean> deleteBatch(@RequestBody List<String> idList) {
        SysDictionaryValidator.deleteValidate(idList);
        return ResultBean.restResult(sysDictionaryService.deleteBatch(idList), ErrorCodeInfo.NO_CONTENT);
    }

    /**
     * @param sysDictionary 字典信息
     * @description 更新字典类型
     * @author 胡昊
     * @email huhao9277@gmail.com
     * @date 2021/3/5 12:47
     */
    @PatchMapping("/update")
    @Operation(summary = "更新字典类型")
    public ResultBean<Boolean> update(@RequestBody SysDictionary sysDictionary) {
        SysDictionaryValidator.updateValidate(sysDictionary);
        return ResultBean.restResult(sysDictionaryService.updateById(sysDictionary), ErrorCodeInfo.OK);
    }

    /**
     * @param entityPageBean 分页查询信息
     * @description 分页查询字典类型
     * @author 胡昊
     * @email huhao9277@gmail.com
     * @date 2021/3/5 12:52
     */
    @PostMapping("/page")
    @Operation(summary = "分页查询字典类型")
    public ResultBean<Page<SysDictionaryView>> page(@RequestBody EntityPageBean<SysDictionary> entityPageBean) {
        return ResultBean.restResult(sysDictionaryService.page(entityPageBean), ErrorCodeInfo.OK);
    }
}

